package com.ve.c51;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.ve.c51.base.BaseActivity;
import com.ve.compiler.ExampleInstaller;
import com.ve.file.FileAdapter;
import com.ve.file.GFile;
import com.ve.file.ItemListener;

import org.greenrobot.eventbus.EventBus;

public class SelectFileActivity extends BaseActivity {
    private RecyclerView list;
    private FileAdapter fileAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_file);
        list=findViewById(R.id.activity_select_file_list);
        list.setLayoutManager(new LinearLayoutManager(this));
        fileAdapter=new FileAdapter();
        fileAdapter.addChild(new GFile(ExampleInstaller.getDir().getAbsolutePath()));
        fileAdapter.addChild(new GFile("/sdcard"));

        list.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL));
        fileAdapter.setItemListener(new ItemListener() {
            @Override
            public void onOpen(int index, GFile file) {
                EventBus.getDefault().post(file.getPath());
                finish();
            }

            @Override
            public void onLongClick(View view, int index, GFile file) {

            }
        });
        list.setAdapter(fileAdapter);
        initToolbar(R.id.activity_select_file_toolbar);
        setTitle("选择烧录文件");

    }
}
